package utils;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


import javax.servlet.http.Cookie;

public class GetScopusSessionCookie {
	private String scopusMachine;
	public GetScopusSessionCookie() {
		
		  try {
			URL url = new URL("http://www.scopus.com/home.url");
			HttpURLConnection con = (HttpURLConnection)url.openConnection();
			con.connect();
			String headerName=null;
			for (int i=1; (headerName = con.getHeaderFieldKey(i))!=null; i++) {
			 	if (headerName.equals("Set-Cookie")) {                  
			 		String cookie = con.getHeaderField(i);
			 		cookie = cookie.substring(0, cookie.indexOf(";"));
			 		String cookieName = cookie.substring(0, cookie.indexOf("="));
			 		if(cookieName.equals("scopus.machineID")){
			 			scopusMachine= cookie.substring(cookie.indexOf("=") + 1, cookie.length());
			 		}
			 		
			 		
			 	}
			}
		} catch (MalformedURLException e) {
			
		} catch (IOException e){
			
		}
		 
	}
	public String getScopusMachine() {
		return scopusMachine;
	}
	

			
	
}
